#!/bin/bash
# 脚本描述：运行 disql 连接到数据库并执行 test.sql 文件中的 SQL 语句
echo "Connecting to database with disql..."
# 检查 disql 命令是否存在
if ! command -v disql &> /dev/null; then
    echo "Error: disql command not found. Please ensure it is installed and in your PATH."
    exit 1
fi
# 检查 test.sql 文件是否存在
if [ ! -f "test.sql" ]; then
    echo "Error: test.sql file not found in the current directory."
    exit 1
fi
# 运行 disql 命令连接到数据库并执行 test.sql 文件
# 用户名/密码@主机:端口 < test.sql
disql captbox/captbox2025 < test.sql
# 检查命令是否成功执行
if [ $? -eq 0 ]; then
    echo "Successfully connected to the database and executed test.sql."
else
    echo "Error: Failed to connect to the database or execute test.sql. Please check credentials, server availability, or SQL file content."
    exit 1
fi
